import { mapGetters } from "vuex";
import { query2 } from "@/views/property-info-sys/other-property/api/other_property.js";
let moment = require("moment");

export default {
	name: "property-list",
	computed: {
		...mapGetters(["permissions"])
	},
	provide() {
		return {
			initList: this.query
		};
	},
	mounted() {
		this.useTypes = this.getDict("property_use_types");
		this.roomStatus = this.getDict("room_status");
		this.propertyTypes = this.getDict("property_types");
		this.propertyOwnerships = this.getDict("property_ownerships");
		this.propertySourceDict = this.getDict("property_source");
	},
	data() {
		return {
			propertyObject: {},
			dialogVisible: false,
			add_but: false,
			useTypes: [],
			roomStatus: [],
			propertyTypes: [],
			propertyOwnerships: [],
			propertySourceDict: [],
			edit_but: false,
			del_but: false,
			placeholder: "输入物业名称",
			tableData: [],
			// 请求参数
			params: {
				current: 1,
				size: 10,
				propertyName: ""
			},
			// 分页
			pager: {
				total: 0, // 总页数
				current: 1, // 当前页数
				size: 10 // 每页显示多少条
			},
			// 页面loading
			loading: false
		};
	},
	methods: {
		submit() {
			this.dialogVisible = false;
			this.$emit("getPropertyObject", this.propertyObject);
		},
		//表格行点击
		rowClick(row) {
			this.propertyObject = row;
		},
		show() {
			this.dialogVisible = true;
			this.query();
		},

		handleClose(done) {
			this.propertyObject = {};
			done();
		},
		query(params = {}) {
			this.loading = true;
			let requestData = { ...this.params, ...params };
			query2(requestData)
				.then(res => {
					const { current, size, total, records } = res.data.data;
					this.tableData = records;
					this.params = requestData;
					this.pager = { total, current, size };
				})
				.finally(() => {
					this.loading = false;
				});
		},
		dateFormat: function(row, column, cellValue) {
			if (!cellValue) {
				return "";
			}
			return moment(cellValue).format("YYYY-MM-DD");
		},
		//字典翻译，此处根据列写死的 物业用途  物业类型 产权情况 物业状态 物业来源
		dictFormate: function(row, column, cellValue) {
			let columnTxt = column.property;
			//物业类型
			let dict;
			if ("propertyType" === columnTxt) {
				dict = this.propertyTypes.find(p => p.value == cellValue);
			}
			if ("useType" === columnTxt) {
				dict = this.useTypes.find(p => p.value == cellValue);
			}
			if ("propertyOwnership" === columnTxt) {
				dict = this.propertyOwnerships.find(p => p.value == cellValue);
			}
			if ("propertyStatus" === columnTxt) {
				dict = this.roomStatus.find(p => p.value == cellValue);
			}
			if ("propertySource" === columnTxt) {
				dict = this.propertySourceDict.find(p => p.value == cellValue);
			}
			if (dict) {
				return dict.label;
			}
			return "";
		}
	}
};
